import random

from ResNet152Model import ResNet152Model
import settings
import helpers
import tensorflow as tf

print("* Loading model...")
model = ResNet152Model()
print("* Model loaded")


def classify_process_edge(x, i):
    # continually pool for new images to classify
    res = model.splitpredict(x, 0, i)
    return res


def classify_process_cloud(x, i):
    # continually pool for new images to classify
    res = model.splitpredict(x, i, settings.ResNet_Layers)
    return res


input_x = tf.random.normal([1, settings.IMAGE_WIDTH, settings.IMAGE_HEIGHT, settings.IMAGE_CHANS],
                           dtype=settings.IMAGE_DTYPE)
# result_DLP = classify_process(input_x)
# print(result_DLP)
index = random.randint(0, settings.ResNet_Layers)

temp = classify_process_edge(input_x, index)
print(temp.dtype)
print(temp.shape)
a = helpers.base64_encode_image(temp)
temp = helpers.base64_decode_image(a, settings.ResNet_IMAGE_DTYPE, (temp.shape[0], temp.shape[1], temp.shape[2], temp.shape[3]))
result = classify_process_cloud(temp, index)
print(result)
# result = model.predict(input_x)
# print(result)
# print(model.get_layer(index=0)(input_x))
# print(model.predict(input_x)[0][:5])
